/*
 * @Author: luojianfeng
 * @Date: 2022-12-06 13:53:25
 * @LastEditTime: 2023-02-02 10:36:28
 * @LastEditors: luojianfeng
 * @Description:
 */
import { PropType } from 'vue'
import * as monaco from 'monaco-editor'
export type Theme = 'vs' | 'hc-black' | 'vs-dark' | 'GreyTheme'
export type FoldingStrategy = 'auto' | 'indentation'
export type RenderLineHighlight = 'all' | 'line' | 'none' | 'gutter'

export interface Options extends monaco.editor.IEditorOptions {
  automaticLayout: boolean // 自适应布局
  foldingStrategy: FoldingStrategy // 折叠方式  auto | indentation
  renderLineHighlight: RenderLineHighlight // 行亮
  selectOnLineNumbers: boolean // 显示行号
  minimap: {
    // 关闭小地图
    enabled: boolean
  }
  readOnly: boolean // 只读
  fontSize: number // 字体大小
  scrollBeyondLastLine: boolean // 取消代码后面一大段空白
  overviewRulerBorder: boolean // 不要滚动条的边框
  contextmenu: boolean //右键菜单
  folding: boolean //启用代码折叠
}

export const editorProps = {
  modelValue: {
    type: String as PropType<string>,
    default: null
  },
  width: {
    type: [String, Number] as PropType<string | number>,
    default: '100%'
  },
  height: {
    type: [String, Number] as PropType<string | number>,
    default: '100%'
  },
  language: {
    type: String as PropType<string>,
    default: 'javascript'
  },
  theme: {
    type: String as PropType<Theme>,
    // validator(value: string): boolean {
    //   return ['vs', 'hc-black', 'vs-dark'].includes(value)
    // },
    default: 'hc-black'
  },
  options: {
    type: Object as PropType<Options>,
    default: function () {
      return {
        automaticLayout: true,
        foldingStrategy: 'indentation',
        renderLineHighlight: 'none',
        selectOnLineNumbers: false,
        minimap: {
          enabled: false
        },
        scrollbar: {
          vertical: 'hidden',
          alwaysConsumeMouseWheel: false
        },
        readOnly: false,
        fontSize: 14,
        scrollBeyondLastLine: false,
        overviewRulerBorder: false,
        contextmenu: false,
        // lineNumbers: 'off', //行号隐藏
        glyphMargin: false,
        lineDecorationsWidth: 0,
        // overviewRulerLanes: 0,
        // fixedOverflowWidgets: 0,
        // lineNumbersMinChars: 0,
        // folding: false, //启用代码折叠
        lineHeight: 24
      }
    }
  }
}
